<html>
<head>
    <meta charset="UTF-8">
    <title>系统首页</title>
    <link id="easyuiTheme" href="../../static/easyui/themes/default/easyui.css" rel="stylesheet" type="text/css"/>
    <script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
    <script src="../../static/easyui/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
    <script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <script src="../../static/easyui/jquery.easyui.ext.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
    <script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
    <script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
    <script src="../../static/plugin/assets/jslib.menu.js" type="text/javascript"></script>
    <link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
    <link href="../../static/css/normalize.css?twitterbutton" rel="stylesheet" type="text/css"/>
    <link href="../../static/css/tricks.css?twitterbutton" rel="stylesheet" type="text/css"/>
    <link href="../../static/css/elusive-webfont.css?twitterbutton" rel="stylesheet" type="text/css"/>
    <link href="../../static/css/codemirror.css?twitterbutton" rel="stylesheet" type="text/css"/>
    <link href="../../static/css/screen.css?twitterbutton" rel="stylesheet" type="text/css"/>
    <style type="text/css">
        table,table tr th,table tr td{text-align:center;border: 1px solid #ccd1d3;border-collapse:collapse;}
        table th{font-weight:normal;font-size:14px;background-color: #5173a0;color:white;}
        table td,table th{padding:2px;height:30px;min-width:30px;overflow:hidden;white-space:nowrap;}
        table{width:850px;margin-left: 15px;}
        table td:hover{overflow:auto;}
        table th:hover{overflow:auto;}
        table td::-webkit-scrollbar { width: 0px;height:0px;}
        table th::-webkit-scrollbar { width: 0px;height:0px;}
        .tbHr{border-bottom:none;float:left;margin-left:15px;width:850px;}
        .tabTitle{margin-left:5px;font-size:18px;color: #323232;height:30px;overflow: hidden;}
        .dmenus{width:1000px;margin-bottom: 50px;position:relative;left:15%;overflow:hidden;}
        .pageBody{width:100%;height:95%;text-align:center;background-color: #fdfdfd;border:1px solid #ccd1d3;overflow:scroll;}
    </style>
    <script>

        $(function() {
            getSystemStatus();
            getAgentStatus();
        });

        function getSystemStatus(){
            $.ajax({
                type: "POST",
                url: '../../api/batch/home/pages',
                data: {
                },
                success: function(data) {
                    if(data.success)
                        createBusSysHtml(data.rows);
                    else
                        $.messager.alert('提示',data.message,'info');
                }
            });
        }


        function getAgentStatus(){
            $.ajax({
                type: "POST",
                url: '../../api/s/agent/infos',
                data: {},
                success: function(data) {
                    if(data.success)
                        createServiceNodeHtml(data.rows);
                    else
                        $.messager.alert('提示',data.message,'info');
                }
            });
        }

        function createBusSysHtml(data){
            $("#systemStatus").empty();
            $("#all").text(data.length);
            if(data.length==0){
                var tableHtml="";
                tableHtml+="<tr rowspan='2'><td colspan='7'>暂无数据</td></tr>";
                $("#dg tbody").append(tableHtml);
            }else{
                for(var i=0;i<data.length;i++){
                    var tableHtml="";
                    var sub=data[i];
                    tableHtml+="<tr><td>"+sub.subsCode+"</td><td>"+sub.subsName+"</td>";
                    tableHtml+="<td>"+sub.subsBatDate+"</td><td>"+sub.batchNumber+"</td>";
                    tableHtml+="<td>"+sub.hpRunning+"</td><td>"+sub.hpError+"</td><td>"+sub.hpFinish+"</td></tr>";
                    $("#dg tbody").append(tableHtml);
                }
            }
        }

        function createServiceNodeHtml(data){
            $("#subsNode").empty();
            $("#nodeNumber").text(data.length);
            if(data.length==0){
                var tableHtml="";
                tableHtml+="<tr rowspan='2'><td colspan='7'>暂无数据</td></tr>";
                $("#dd tbody").append(tableHtml);
            }else{
                for(var i=0;i<data.length;i++){
                    var tableHtml="";
                    var sub=data[i];
                    tableHtml+="<tr><td>"+sub.agentId+"</td><td>"+sub.agentName+"</td>";
                    tableHtml+="<td>"+sub.agentUrl+"</td>" ;
                    switch(sub.agentState){
                        case "F": tableHtml+="<td>启动失败</td>"; break;
                        case "R": tableHtml+="<td>运行中</td>"; break;
                        case "S": tableHtml+="<td>已停止</td>"; break;
                        case "E": tableHtml+="<td>停止失败</td>"; break;
                    }
                    tableHtml+="<td></td><td></td><td></td></tr>";
                    $("#dd tbody").append(tableHtml);
                }
            }

        }

        function enterProcesses(){
            window.parent.addTab("批次监控","bsp-console/BatInstBatchList.html")
        }
    </script>
</head>

<body class="easyui-layout">
<div class="pageBody">
    <div class="dmenus"style="margin-top:30px;">
        <ul class="tabTitle"><span style="float:left;margin-left: 10px">业务系统数量：<a id="all"></a>个</span>
            <span style="float:left;margin-left:550px;cursor:hand" onclick="enterProcesses()"><a>进入批次监控页面</a></span></ul><hr class="tbHr">
        <div>
            <table id="dg">
                <thead>
                <tr>
                    <th>业务系统代码</th>
                    <th>业务系统名称</th>
                    <th>批次日期</th>
                    <th>批次数量</th>
                    <th>执行中</th>
                    <th>异常</th>
                    <th>正常结束</th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
    <div class="dmenus">
        <ul class="tabTitle"><span style="float:left;margin-left: 10px">服务节点数量：<a id="nodeNumber"></a>个</span></ul><hr class="tbHr">
        <div>
            <table id="dd">
                <thead>
                <tr>
                    <th>执行节点标识</th>
                    <th>执行节点名称</th>
                    <th>执行节点IP</th>
                    <th>执行节点状态</th>
                    <th>CPU</th>
                    <th>内存</th>
                    <th>磁盘</th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
</html>